<?php
    header("Access-Control-Allow-Origin:*");
    $name = $_POST['name'];
    $pwd = $_POST['pwd'];
    $tele = $_POST['tele'];

    $con = mysqli_connect('localhost','root','hl0319');

    mysqli_select_db($con,'login');

    mysqli_query($con,"set charset 'utf8'");
    mysqli_query($con,"set character set 'utf8'");
    
    $sql1 = "select * from users where username='$name'";
    $res1 = mysqli_query($con,$sql1);

    $num = mysqli_num_rows($res1);
    if($num){
        echo json_encode(array(
            "code" => 100,
            "body" => array(
                "msg" => "用户名重复，请换一个用户名"
            )
        ));
    }else{
        $sql = "insert into users (username,password,telephone) values ('$name',$pwd,'$tele')";
        $res = mysqli_query($con,$sql);
        if($res){
            echo json_encode(array(
                "code" => 200,
                "body" => array(
                    "msg" => "注册成功"
                )
            ));
        }else{
            echo json_encode(array(
                "code" => 0,
                "body" => array(
                    "msg" => "网络失败请重试"
                )
            ));
        }
    }
?>